package com.preskool.controller;

import com.github.pagehelper.PageInfo;
import com.preskool.dto.ActionResult;
import com.preskool.po.Holiday;
import com.preskool.service.HolidayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/holiday")

public class HolidayController {

    @Autowired
    private HolidayService holidayService;

    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public ActionResult findAll(Integer currentPage, Integer pageSize) {
        ActionResult actionResult = new ActionResult();
        List<Holiday> all = holidayService.findAll(1, 4);
        PageInfo<Holiday> holidayPageInfo = new PageInfo<>(all);
        actionResult.setData(all);
        actionResult.setTotalPage(holidayPageInfo.getPageSize());
        actionResult.setPageNum(holidayPageInfo.getPageNum());
        //总记录数
        actionResult.setCount(holidayPageInfo.getTotal());
        actionResult.setMsg("查询成功");
        actionResult.setStatusCode(200);
        return actionResult;
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ActionResult update(Holiday holiday) {
//根据前台传来对象获得id查询
        Integer update = holidayService.update(holiday);
//        if (one != null) {
//            Integer update = holidayService.update(one);
//            if (update != null) {
//                return new ActionResult(200, "修改成功", null, null, null, null);
//
//            }
//
//        }

        return new ActionResult(200, "修改成功", update, null, null, null);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ActionResult add(Holiday holiday) {
        holidayService.add(holiday);
        return new ActionResult(200, "添加成功", null, null, null, null);

    }

    @RequestMapping(value = "/findOne", method = RequestMethod.GET)
    public ActionResult findOne(Integer hid) {
        Holiday one = holidayService.findOne(hid);
        return new ActionResult(200, "查一个成功", one, null, null, null);


    }

    @RequestMapping(value = "/del", method = RequestMethod.GET)
    public ActionResult del(Integer hid) {
        Integer del = holidayService.del(hid);
        return new ActionResult(200, "删除成功", null, null, null, null);

    }


}
